package cn.epsilon3.controller;

import cn.epsilon3.annotation.E3Log;
import cn.epsilon3.annotation.E3Service;
import cn.epsilon3.common.Result;
import cn.epsilon3.domain.e3.vo.E3BindEmailVO;
import cn.epsilon3.domain.e3.vo.E3SendEmailVO;
import cn.epsilon3.domain.e3.vo.E3VerifyAuthenticatorCodeVO;
import cn.epsilon3.domain.e3.vo.E3VerifyEmailCodeVO;
import cn.epsilon3.service.twoFactorAuthentication.E32FAService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.validation.Valid;

@Api(tags = "E3-多重认证设置v0.0.6")
@E3Service(path = "/security/2fa")
public class E3FAController {

    @Resource
    private E32FAService faService;

    @E3Log
    @ApiOperation("检查是否绑定邮箱")
    @PostMapping("/checkBindEmail.action")
    public Result<String> checkBindEmail() {
        return faService.e3CheckBindEmail();
    }

    @E3Log
    @ApiOperation("绑定邮箱")
    @PostMapping("/bindEmail.action")
    public Result<String> bindEmail(@Valid @RequestBody E3BindEmailVO e3BindEmailVO) {
        return faService.e3BindEmail(e3BindEmailVO);
    }

    @E3Log
    @ApiOperation("发送绑定邮箱验证码")
    @PostMapping("/sendBindEmail.action")
    public Result<String> sendBindEmail(@Valid @RequestBody E3SendEmailVO e3SendEmailVO) {
        return faService.e3SendBindEmail(e3SendEmailVO);
    }

    @E3Log
    @ApiOperation("验证邮箱验证码")
    @PostMapping("/verifyEmailCode.action")
    public Result<String> verifyEmailCode(@Valid @RequestBody E3VerifyEmailCodeVO e3VerifyEmailCodeVO) {
        return faService.e3VerifyEmailCode(e3VerifyEmailCodeVO);
    }

    @E3Log
    @ApiOperation("检查是否绑定验证器")
    @PostMapping("/checkAuthenticator.action")
    public Result<Object> checkAuthenticator() {
        return faService.e3CheckAuthenticator();
    }

    @E3Log
    @ApiOperation("绑定验证器")
    @PostMapping("/bindAuthenticator.action")
    public Result<String> bindAuthenticator(@Valid @RequestBody E3VerifyAuthenticatorCodeVO e3VerifyAuthenticatorCodeVO) {
        return faService.e3BindAuthenticator(e3VerifyAuthenticatorCodeVO);
    }

    @E3Log(recordGet = true)
    @ApiOperation("需要二步验证的操作 校验动态验证码")
    @GetMapping("/verifyOpe2Fa.action")
    public Result<String> verifyOpe2Fa(@RequestParam("code") String code) {
        return faService.verifyOpe2Fa(code);
    }
}
